//============================================================================
// Name        : ASMUtil.java
// Author      : iron.yin@gmail.com
// Version     : v1.0
// Copyright   : RisingSun CO,.LTD
// Description : ASMUtil.java in Java
//============================================================================
package cc.risingsun.wing.core;

import org.objectweb.asm.Type;

/**
 * asm helper class
 * 
 * @author iron.yin@gmail.com
 * @sina 2012-7-25
 */
public class ASMUtil {

	public static WingParameter[] getMethodParameter(Type methodType) {
		Type[] paramTypes = methodType.getArgumentTypes();
		int len = paramTypes.length;
		WingParameter[] params = new WingParameter[len];
		for (int i = 0; i < len; i++) {
			Type type = paramTypes[i];
			params[i] = new WingParameter(methodType.getDescriptor(), "p" + i,
					type);
		}
		return params;
	}

	public static String reverse(String name) {
		return name.replace('/', '.');
	}

	public static String obverse(String name) {
		return name.replace('.', '/');
	}

	public static Class<?> toClass(String name){
		try {
			return Class.forName(name.replace('/', '.'));
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
}
